package com.leetcode.q12;

/**
 * <p> description: desc</p>
 *
 * @author tanzc
 * @date 2022/3/30
 **/
public class IntToRoman {
    static String[][] roman = new String[4][3];

    static {
        roman[0] = new String[]{"I", "V", "X"};
        roman[1] = new String[]{"X", "L", "C"};
        roman[2] = new String[]{"C", "D", "M"};
        roman[3] = new String[]{"M", " ", " "};
    }

    public String intToRoman(int num) {
        int numm = num;

        String ss = "";

        int k = 0;
        while (numm != 0) {
            String s = "";
            int n = numm % 10;
            if (n != 0) {
                switch (n) {
                    case 1:
                        s = roman[k][0];
                        break;
                    case 2:
                        s = roman[k][0] + roman[k][0];
                        break;
                    case 3:
                        s = roman[k][0] + roman[k][0] + roman[k][0];
                        break;
                    case 4:
                        s = roman[k][0] + roman[k][1];
                        break;
                    case 5:
                        s = roman[k][1];
                        break;
                    case 6:
                        s = roman[k][1] + roman[k][0];
                        break;
                    case 7:
                        s = roman[k][1] + roman[k][0] + roman[k][0];
                        break;
                    case 8:
                        s = roman[k][1] + roman[k][0] + roman[k][0] + roman[k][0];
                        break;
                    case 9:
                        s = roman[k][0] + roman[k][2];
                        break;
                    default:
                        break;
                }
            }
            ss = s + ss;
            numm = numm / 10;
            k++;
        }

        return ss;
    }
}
